const utils = require('j7/utils');
const BaseModel = require('./basemodel');

class UsedTokenId extends BaseModel {

  async add(account, tokenId, transId, netId) {
    const nowTime = utils.getUtcTime();
    const fields = [
      ['account', account],
      ['token_id', tokenId],
      ['trans_id', transId],
      ['net_id', netId],
      ['confirmed', 1],
      ['createtime', nowTime],
      ['modifytime', nowTime],
    ];
    await this.getSession().bcEventConn
    (
      'insert',
      't_used_token_id',
      fields
    );
  }

  async find(tokenId) {
    const {err, row} = await this.getSession().bcEventConn
    (
      'ormSelectOne',
      't_used_token_id',
      [
        ['token_id', tokenId]
      ]
    );
    return row;
  }

}

module.exports = UsedTokenId;
